<template>
    <div>
        <div class="ui-upload-images" v-for="(item, index) in imgs" :key="index">
            <template>
                <img :src="item">
                <div class="ui-upload-images-cover">
                    <Icon type="ios-eye-outline" @click.native="handleView(item)"></Icon>
                </div>
            </template>
        </div>

        <Modal title="图片预览" v-model="visible">
            <img :src="viewUrl" v-if="visible" style="width: 100%">
        </Modal>
    </div>
</template>

<script>
export default {
    name: 'ImageView',
    props: {
        imgs: {
            type: Array,
            default: function() {
                return [];
            }
        }
    },
    data() {
        return {
            viewUrl: '',
            visible: false,
        }
    },
    methods: {
        handleView (url) {
            this.viewUrl = url;
            this.visible = true;
        },
    }
}
</script>

<style scoped>
.ui-upload-images {
    display: inline-block;
    width: 60px;
    height: 60px;
    text-align: center;
    line-height: 58px;
    border: 1px solid rgba(0,0,0,.2);
    border-radius: 4px;
    overflow: hidden;
    background: #fff;
    position: relative;
    margin-right: 4px;
}
.ui-upload-images img {
    margin-top: -3px;
    max-width: 100%;
    max-height: 100%;
    vertical-align: middle;
}
.ui-upload-images-cover {
    display: none;
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0,0,0,.6);
}
.ui-upload-images:hover .ui-upload-images-cover {
    display: block;
}
.ui-upload-images-cover i {
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    margin: 0 2px;
}
</style>